﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Entity;
using BLL.Access;
using BLL;
using System.Data;

namespace Web.Controls.LAIHAN
{
    public partial class UCLHFenHuDJXX : System.Web.UI.UserControl,IUCLHOperate
    {
        #region 属性
        public bool YongHu3Checked
        {
            get { return this.cQiYongFH3.Checked; }

        }

        public string YongHuHY
        {
            get { return HiddenFieldList.Contains("YongHuH")? HiddenFieldList.Get("YongHuH").ToString():""; }
            set { HiddenFieldList.Set("YongHuH",value); }
        }
        private eLaiHanLX laiHanLX;

        public eLaiHanLX LaiHanLX
        {
            get { return laiHanLX; }
            set { laiHanLX = value; }
        }

        public eLaiHanLCBH LaiHanLCBH
        {
            get;
            set;
        }

        public string LaiHanID
        {
            get { return HiddenFieldList.Contains("LaiHanID") ? HiddenFieldList.Get("LaiHanID").ToString() : ""; }
            set { HiddenFieldList.Set("LaiHanID", value); }
        }
        public string LaiHanLCBHZT
        {
            get { return HiddenFieldList.Contains("LaiHanLCBHZT") ? HiddenFieldList.Get("LaiHanLCBHZT").ToString() : ""; }
            set { HiddenFieldList.Set("LaiHanLCBHZT", value); }
        }
        public string YongHuH1
        {
            get { return txtYongHuH1.Text; }
            set { txtYongHuH1.Text = value; }
        }
        public string YongHuH2
        {
            get { return txtYongHuH2.Text; }
            set { txtYongHuH2.Text = value; }
        }
        public string YongHuH3
        {
            get { return txtYongHuH3.Text; }
            set { txtYongHuH3.Text = value; }
        }
        #endregion

        #region 变量
        /// <summary>
        /// 流程信息BLl
        /// </summary>
        YS_LH_LAIHANLCJLBLL BllLiuChengXX = new YS_LH_LAIHANLCJLBLL();
        /// <summary>
        /// 来函分户信息
        /// </summary>
        YS_LH_FENHUXXBLL BllFenHuXX = new YS_LH_FENHUXXBLL();
        /// <summary>
        /// 来函信息BLL
        /// </summary>
        YS_LH_LAIHANXXProcess BllLaiHanxx = new YS_LH_LAIHANXXProcess();
        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL BllYongHu = new YS_YG_YONGHUXXBLL();
        /// <summary>
        /// 存储过程BLL
        /// </summary>
        SpHelper _spHelper = new SpHelper();
        /// <summary>
        /// 原计划BLL
        /// </summary>
        YS_JH_YUANJIHUABLL BllYuanJiH = new YS_JH_YUANJIHUABLL();
        /// <summary>
        /// 来函用户信息
        /// </summary>
        YS_LH_YONGHUTZProcess BllLaiHanYHTZ = new YS_LH_YONGHUTZProcess();
        /// <summary>
        /// 用户水表关系BLL
        /// </summary>
        YS_LH_YONGHUSBGXProcess BllYongHuSBGX = new YS_LH_YONGHUSBGXProcess();
        /// <summary>
        /// 水表信息BLL
        /// </summary>
        YS_CB_SHUIBIAOXXBLL BllShuiBiaoXX = new YS_CB_SHUIBIAOXXBLL();

        /// <summary>
        /// 日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }
        /// <summary>
        /// 是否启用用户3
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cQiYongFH3_CheckedChanged(object sender, EventArgs e)
        {
            SetControlStatus(3, cQiYongFH3.Checked);
            if (txtYongHuH3.Text.Trim().Length==0)
            {
                LoadYongHuXX(3);
            }
            
        }
        /// <summary>
        /// 局号1改变选项事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dGongSiH_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            if (this.dJuHao.Value == null)
            {
                this.dGongSiH.Items.Clear();
            }
            else
            {
                PageTools.LoadComboxGongSi(this.dGongSiH, this.dJuHao.Value.ToString(), null);
            }
        }
        protected void dGongSiH2_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            if (this.dJuHao2.Value == null)
            {
                this.dGongSiH2.Items.Clear();
            }
            else
            {
                PageTools.LoadComboxGongSi(this.dGongSiH2, this.dJuHao2.Value.ToString(), null);
            }
        }
        protected void dGongSiH3_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            if (this.dJuHao3.Value == null)
            {
                this.dGongSiH3.Items.Clear();
            }
            else
            {
                PageTools.LoadComboxGongSi(this.dGongSiH3, this.dJuHao3.Value.ToString(), null);
            }
        }

        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            if (e.Parameter == "yonghuh")
            {
                e.Result = e.Parameter + "|" + LoadYongHuXX(0);
            }
        }

        protected void BtnClear_Click(object sender, EventArgs e)
        {
            ClearInfo();
        }

        /// <summary>
        /// 用户搜索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            //材料信息
            IUCLHOperate ucinfo = this.Parent.FindControl("UCLHBtnBottom") as IUCLHOperate;
            if (ucinfo != null)
            {
                YS_LH_LAIHANXX lhxx = new YS_LH_LAIHANXX();
                lhxx.S_YONGHUBH = this.txtYongHuH.Text;
                ucinfo.LoadInfo(lhxx);
            }
            LoadYongHuXX(1);
            txtYongHuH1.Focus();
        }
        #endregion

        #region 方法
        /// <summary>
        /// 首次加载
        /// </summary>
        public void InitControl()
        {
            System.Drawing.Color color = System.Drawing.Color.FromName("#e3f2f9");
            SetControlStatus(1,false);
            SetControlStatus(2,false);
            SetControlStatus(3,false);
            SetControlValue();

            if (Request["id"] != null&&(LaiHanID==""||LaiHanID=="0"))
            {
                LaiHanID = Request["id"];
            }
            if (LaiHanID != "" && LaiHanID != "0")
            {
                LoadLaiHanXXByID();

            }
            else
            {
                UCLHSJBTNS uc = this.Parent.FindControl("UCLHSJBTNS") as UCLHSJBTNS;
                if (uc != null)
                {
                    uc.LoadInfo(new YS_LH_LAIHANXX());
                }
            }
            
        }
        /// <summary>
        /// 设置是否可读
        /// </summary>
        /// <param name="type"></param>
        /// <param name="status"></param>
        public void SetControlStatus(int type,bool status)
        {
            ControlCollection controls = this.Controls;
            if (type == 1)
            {
                controls = td_FenHu1.Controls;
            }
            if (type == 2)
            {
                controls = td_FenHu2.Controls;
            }
            if (type == 3)
            {
                controls = td_FenHu3.Controls;
                UCLHShenQingXX uc = this.Parent.FindControl("UCLHShenQingXX") as UCLHShenQingXX;
                if (uc != null)
                {
                    uc.SetFenHuTxTModel(status);
                }
            }
            foreach (Control c in controls)
            {
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox txt = c as DevExpress.Web.ASPxTextBox;
                    txt.ReadOnly = !status;
                    if (txt.ClientID != txtYongHuH.ClientID)
                    {
                        txt.ReadOnly = !status;
                    }
                }
                else
                    if (c is DevExpress.Web.ASPxComboBox)
                    {
                        DevExpress.Web.ASPxComboBox com = c as DevExpress.Web.ASPxComboBox;
                        com.ReadOnly = !status;
                        //com.Enabled = status;

                    }
                    else
                        if (c is DevExpress.Web.ASPxCheckBox)
                        {
                            DevExpress.Web.ASPxCheckBox check = c as DevExpress.Web.ASPxCheckBox;
                            if (check.ClientID != cQiYongFH3.ClientID)
                            {
                                check.ReadOnly = !status;
                                //check.Enabled = status;
                            }

                        }

            }
            txtYongHuH.Focus();
        }

        /// <summary>
        /// 初始化加载相关信息
        /// </summary>
        private void SetControlValue()
        {
            //根据操作人加载管理部门(站点)
            DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANMC", "ZHANDIANBH", "-", string.Format("USERID={0}", LoginInfo.CurrentUser.UserID)).Tables[0];

            string zhendianBH = dtZhanDian.Rows[0]["VALUE"].ToString();


            //加载行政区

            DataTable XingZhengQ = BusinessTool.GetTextAndValue(
                    "YS_JX_XINGZHENGQ", "S_MINGCHENG", "S_BIANHAO", null, null
                ).Tables[0];

            PageTools.BindComboBox(
                this.dXingZhengQ, XingZhengQ
            );
            PageTools.BindComboBox(
                this.dXingZhengQ2, XingZhengQ
            );
            PageTools.BindComboBox(
                this.dXingZhengQ3, XingZhengQ
            );

            this.dXingZhengQ.SelectedIndex = 0;
            this.dXingZhengQ2.SelectedIndex = 0;
            this.dXingZhengQ3.SelectedIndex = 0;
            //this.dJuHao.ReadOnly = false;
            DataTable JuXinX= BusinessTool.GetTextAndValue(
                    "YS_JX_JUXINX", "S_MINGCHENG", "S_BIANHAO", null, "I_LEIXING=0 and (S_ZHANDIANBH='" + zhendianBH + "' or '00'='" + zhendianBH + "')"
                ).Tables[0];
            PageTools.LoadCombox(
                this.dJuHao,PageTools.eLoadType.局,BusinessTool.ZHANDIANBH(),null,""
            );
            PageTools.LoadCombox(
                this.dJuHao2, PageTools.eLoadType.局, BusinessTool.ZHANDIANBH(), null, ""
            );
            PageTools.LoadCombox(
                this.dJuHao3, PageTools.eLoadType.局, BusinessTool.ZHANDIANBH(), null, ""
            );
            if (this.dJuHao.Items.Count > 0)
            {
                this.dJuHao.SelectedIndex = 0;
                this.dJuHao2.SelectedIndex = 0;
                this.dJuHao3.SelectedIndex = 0;
            }
            if (zhendianBH!="51"&&zhendianBH!="00")
            {
                this.dJuHao.ReadOnly = true;
                this.dJuHao2.ReadOnly = true;
                this.dJuHao3.ReadOnly = true;
            }

            //加载业务员
            DataTable YeWuY = BusinessTool.GetTextAndValue(
                    "View_AS_UserInfo", "USERNAME", "USERID", null, string.Format("(ZHANDIANBH='{0}' or '00'='{0}') and ROLENAME like '%业务员%'", zhendianBH)
                ).Tables[0];
            PageTools.BindComboBox(
                this.dYeWuY, YeWuY
            );
            PageTools.BindComboBox(
               this.dYeWuY2, YeWuY
           );
            PageTools.BindComboBox(
               this.dYeWuY3, YeWuY
           );
            if (this.dYeWuY.Items.Count != 0)
            {
                this.dYeWuY.SelectedIndex = 0;
                this.dYeWuY2.SelectedIndex = 0;
                this.dYeWuY3.SelectedIndex = 0;
            }
            //加载用水性质
            DataTable YongShuiXZ = BusinessTool.GetTextAndValue(
                 "YS_JX_YONGSHUIXZ", "S_MINGCHENG", "S_BIANMA", "-", string.Format("I_TYPE={0}", zhendianBH.Contains("51") ? 1 : 0)
                 ).Tables[0];
            PageTools.BindComboBox(
                 this.dYongShuiXZ, YongShuiXZ
             );
            PageTools.BindComboBox(
                 this.dYongShuiXZ2, YongShuiXZ
             );
            PageTools.BindComboBox(
                 this.dYongShuiXZ3, YongShuiXZ
             );
            if (this.dYongShuiXZ.Items.Count != 0)
            {
                this.dYongShuiXZ.SelectedIndex = 0;
                this.dYongShuiXZ2.SelectedIndex = 0;
                this.dYongShuiXZ3.SelectedIndex = 0;
                LoadGongSiByJu(1);
                LoadGongSiByJu(2);
                LoadGongSiByJu(3);
            }
            //加载考核复用

            WordsManager manger = new WordsManager();
            DataTable FuYongKH = manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.考核复用, "-");
            PageTools.BindComboBox(this.dKaoHeFY, FuYongKH);
            PageTools.BindComboBox(this.dKaoHeFY2, FuYongKH);
            PageTools.BindComboBox(this.dKaoHeFY3, FuYongKH);
            if (this.dKaoHeFY.Items.Count != 0)
            {
                this.dKaoHeFY.SelectedIndex = 0;
                this.dKaoHeFY2.SelectedIndex = 0;
                this.dKaoHeFY3.SelectedIndex = 0;
            }
            //加载行业类型
            DataTable HangYeLB = BusinessTool.GetTextAndValue(
                 "YS_JX_HANGYELX", "S_SHESHUIDXFLMC", "S_SHESHUIDXFLDM", null, null
                 ).Tables[0];
            PageTools.BindComboBox(
                 this.dHangYeLB, HangYeLB
             );
            PageTools.BindComboBox(
                this.dHangYeLB2, HangYeLB
            );
            PageTools.BindComboBox(
                this.dHangYeLB3, HangYeLB
            );
            if (this.dHangYeLB2.Items.Count != 0)
            {
                this.dHangYeLB.SelectedIndex = 0;
                this.dHangYeLB2.SelectedIndex = 0;
                this.dHangYeLB3.SelectedIndex = 0;

            }
        }
        /// <summary>
        /// 根据局信息加载公司信息
        /// </summary>
        /// <param name="type"></param>
        private void LoadGongSiByJu(int type)
        {
            string juhao="";
            if (dJuHao.Value == null)
            {
                return;
            }
            if(type==1)
            {
                juhao=dJuHao.Value.ToString();
            }
            if(type==2)
            {
                juhao=dJuHao2.Value.ToString();
            }
            if(type==3)
            {
                juhao=dJuHao3.Value.ToString();
            }
            DataTable table = BusinessTool.GetTextAndValue(
                       "YS_JX_GONGSIXX", "S_MINGCHENG", "S_BIANHAO", null, string.Format("S_JUBIANH='{0}' and I_LEIXING=0",juhao)
                   ).Tables[0];
            if (type == 1)
            {
                if (table.Rows.Count > 0)
                {

                    PageTools.BindComboBox(this.dGongSiH, table);
                    this.dGongSiH.SelectedIndex = 0;

                }
                else
                {
                    this.dGongSiH.Items.Clear();

                }
            }
            if (type == 2)
            {
                if (table.Rows.Count > 0)
                {

                    PageTools.BindComboBox(this.dGongSiH2, table);
                    this.dGongSiH2.SelectedIndex = 0;

                }
                else
                {
                    this.dGongSiH2.Items.Clear();

                }
            }
            if (type == 3)
            {
                if (table.Rows.Count > 0)
                {

                    PageTools.BindComboBox(this.dGongSiH3, table);
                    this.dGongSiH3.SelectedIndex = 0;

                }
                else
                {
                    this.dGongSiH3.Items.Clear();

                }
            }
        }
        /// <summary>
        /// 判断用户号是否可用
        /// </summary>
        /// <param name="type"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool CheckYongHuHIsUsed(out int type,out string msg)
        {
            type = 0;
            msg = "";
            if (txtYongHuH1.Text.Trim().Length == 0)
            {
                type = 1;
                msg = "分户1用户号不能为空";
                txtYongHuH1.Focus();
                return false;
            }
            if (txtYongHuH2.Text.Trim().Length == 0)
            {
                txtYongHuH2.Focus();
                type = 2;
                msg = "分户2用户号不能为空";
                return false;
            }
            if (txtYongHuH1.Text.Trim().Substring(0, 2) != txtYongHuH.Text.Trim().Substring(0, 2))
            {
                txtYongHuH1.Focus();
                type = 1;
                msg = "分户1用户号格式错误（前两位为管理块号）";
                return false;
            }
            if (txtYongHuH2.Text.Trim().Substring(0, 2) != txtYongHuH.Text.Trim().Substring(0, 2))
            {
                txtYongHuH2.Focus();
                type = 2;
                msg = "分户2用户号格式错误（前两位为管理块号）";
                return false;
            }
            if (txtYongHuH1.Text.Trim().Length != 7)
            {
                txtYongHuH1.Focus();
                type = 1;
                msg = "分户1用户号应该为7位";
                return false;
            }
            if (txtYongHuH2.Text.Trim().Length != 7)
            {
                txtYongHuH2.Focus();
                type = 2;
                msg = "分户2用户号应该为7位";
                return false;
            }
            string XiuGaiWhere = "";
            if (!string.IsNullOrEmpty(LaiHanID)&&LaiHanID!=""&&LaiHanID!="0")
            {
                XiuGaiWhere = " and S_YUANYONGHUH<>'{0}'";
                XiuGaiWhere = string.Format(XiuGaiWhere, HiddenFieldList.Get("YongHuH").ToString());
            }
            string where = " S_YONGHUH='{0}' and i_JLZT=0 ";
            string where1 = string.Format(where, txtYongHuH1.Text.Trim());
            DataTable dt1 = BllYongHu.SelectYS_YG_YONGHUXXesDynamic(where1, "", null);
            DataTable dt11 = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where1+XiuGaiWhere,"",null);
            if ((dt1.Rows.Count > 0||dt11.Rows.Count>0))
            {
                msg = "用户号（分户1）已存在";
                type = 1;
                txtYongHuH1.Focus();
                return false;
                
            }
            string where2 = string.Format(where, txtYongHuH2.Text.Trim());
            DataTable dt2 = BllYongHu.SelectYS_YG_YONGHUXXesDynamic(where2, "", null);
            DataTable dt22 = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where2+XiuGaiWhere, "", null);
            if ((dt2.Rows.Count > 0||dt22.Rows.Count>0))
            {
                msg = "用户号（分户2）已存在";
                type = 2;
                txtYongHuH2.Focus();
                return false;
                
            }
            if (cQiYongFH3.Checked)
            {
                if (txtYongHuH3.Text.Trim().Length == 0)
                {
                    txtYongHuH3.Focus();
                    type = 3;
                    msg = "分户3用户号不能为空";
                    return false;
                }
                string where3 = string.Format(where, txtYongHuH3.Text.Trim());
                DataTable dt33 = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where3, "", null);
                DataTable dt3 = BllYongHu.SelectYS_YG_YONGHUXXesDynamic(where3+XiuGaiWhere, "", null);
                if ((dt3.Rows.Count > 0||dt33.Rows.Count>0))
                {
                    msg = "用户号（分户3）已存在";
                    type = 3;
                    txtYongHuH3.Focus();
                    return false;
                }

               
            }
            return true;
        }
        /// <summary>
        /// 验证提交
        /// </summary>
        /// <returns></returns>
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();
            rs.IsSuccess = false;
            

            
            if (txtYongHuH.Text.Trim().Length == 0 )
            {
                rs.Msg = "用户号不能为空";
                txtYongHuH.Focus(); return rs;
            }

            if (txtYongHuH1.Text.Trim().Length == 0 )
            {
                rs.Msg = "用户号不能为空";
                txtYongHuH1.Focus(); return rs;
            }
            if (txtYongHuH.Text.Trim() == txtYongHuH1.Text.Trim() || txtYongHuH.Text.Trim() == txtYongHuH2.Text.Trim()
                || txtYongHuH.Text.Trim() == txtYongHuH3.Text.Trim() || txtYongHuH1.Text.Trim() == txtYongHuH2.Text.Trim()
                || txtYongHuH1.Text.Trim() == txtYongHuH3.Text.Trim() || txtYongHuH3.Text.Trim() == txtYongHuH1.Text.Trim())
            {
                rs.Msg = "用户号不能重复";
                txtYongHuH.Focus(); return rs;
            }
            if (txtYongHuM1.Text.Trim().Length == 0)
            {
                rs.Msg = "用户名不能为空";
                txtYongHuM1.Focus(); return rs;
            }
            if (txtDiZhi1.Text.Trim().Length == 0)
            {
                rs.Msg = "地址不能为空";
                txtDiZhi1.Focus(); return rs;
            }
            if (dXingZhengQ.Value == null||dXingZhengQ.Value.ToString().Trim().Length==0)
            {
                rs.Msg = "请选择行政区";
                dXingZhengQ.Focus(); return rs;
            }
            //if (dJuHao.Value == null || dJuHao.Value.ToString().Trim().Length == 0)
            //{
            //    rs.Msg = "请选择局号";
            //    dJuHao.Focus(); return rs;
            //}
            //if (dGongSiH.Value == null || dGongSiH.Value.ToString().Trim().Length == 0)
            //{
            //    rs.Msg = "请选择公司号";
            //    dGongSiH.Focus(); return rs;
            //}
            if (dYeWuY.Value == null || dYeWuY.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择业务员";
                dYeWuY.Focus(); return rs;
            }
            if (txtLianXiR.Text.Trim().Length == 0)
            {
                rs.Msg = "联系人不能为空";
                txtLianXiR.Focus(); return rs;
            }
            if (txtLianXiDH.Text.Trim().Length == 0)
            {
                rs.Msg = "联系电话不能为空";
                txtLianXiDH.Focus(); return rs;
            }
            if (txtLianXiBM1.Text.Trim().Length == 0)
            {
                rs.Msg = "联系部门不能为空";
                txtLianXiBM1.Focus(); return rs;
            }
            if (txtYouBian.Text.Trim().Length == 0)
            {
                rs.Msg = "邮编不能为空";
                txtYouBian.Focus(); return rs;
            }
            if (dYongShuiXZ.Value == null || dYongShuiXZ.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择用水性质";
                dYongShuiXZ.Focus(); return rs;
            }
            if (dHangYeLB.Value == null || dHangYeLB.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择行业类别";
                dHangYeLB.Focus(); return rs;
            }
            if (txtYongShuiJ.Text.Trim().Length == 0||Convert.ToDouble(txtYongShuiJ.Text)<0)
            {
                rs.Msg = "用水价不能为空";
                txtYongShuiJ.Focus(); return rs;
            }
            if (dKaoHeFY.Value == null || dKaoHeFY.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择考核复用";
                dKaoHeFY.Focus(); return rs;
            }
            if (cTuoShou.Checked)
            {
                if (txtKaiHuHM.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户户名不能为空";
                    txtKaiHuHM.Focus(); return rs;
                }
                if (txtKaiHuYH.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户银行不能为空";
                    txtKaiHuYH.Focus(); return rs;
                }
                if (txtKaiHuZH.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户账号不能为空";
                    txtKaiHuZH.Focus(); return rs;
                }
                if (txtHeTongH.Text.Trim().Length == 0)
                {
                    rs.Msg = "合同号不能为空";
                    txtHeTongH.Focus(); return rs;
                }
            }
            
           
            if (txtYongHuH2.Text.Trim().Length == 0)
            {
                rs.Msg = "用户号不能为空";
                txtYongHuH2.Focus(); return rs;
            }
            if (txtYongHuM2.Text.Trim().Length == 0)
            {
                rs.Msg = "用户名不能为空";
                txtYongHuM2.Focus(); return rs;
            }
            if (txtDiZhi2.Text.Trim().Length == 0)
            {
                rs.Msg = "地址不能为空";
                txtDiZhi2.Focus(); return rs;
            }
            if (dXingZhengQ2.Value == null || dXingZhengQ2.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择行政区";
                dXingZhengQ2.Focus(); return rs;
            }
            //if (dJuHao2.Value == null || dJuHao2.Value.ToString().Trim().Length == 0)
            //{
            //    rs.Msg = "请选择局号";
            //    dJuHao2.Focus(); return rs;
            //}
            //if (dGongSiH2.Value == null || dGongSiH2.Value.ToString().Trim().Length == 0)
            //{
            //    rs.Msg = "请选择公司号";
            //    dGongSiH2.Focus(); return rs;
            //}
            if (dYeWuY2.Value == null || dYeWuY2.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择业务员";
                dYeWuY2.Focus(); return rs;
            }
            if (txtLianXiR2.Text.Trim().Length == 0)
            {
                rs.Msg = "联系人不能为空";
                txtLianXiR2.Focus(); return rs;
            }
            if (txtLianXiDH2.Text.Trim().Length == 0)
            {
                rs.Msg = "联系电话不能为空";
                txtLianXiDH2.Focus(); return rs;
            }
            if (txtLianXiBM2.Text.Trim().Length == 0)
            {
                rs.Msg = "联系部门不能为空";
                txtLianXiBM2.Focus(); return rs;
            }
            if (txtYouBian2.Text.Trim().Length == 0)
            {
                rs.Msg = "邮编不能为空";
                txtYouBian2.Focus(); return rs;
            }
            if (dYongShuiXZ2.Value == null || dYongShuiXZ2.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择用水性质";
                dYongShuiXZ2.Focus(); return rs;
            }
            if (dHangYeLB2.Value == null || dHangYeLB2.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择行业类别";
                dHangYeLB2.Focus(); return rs;
            }
            if (txtYongShuiJ2.Text.Trim().Length == 0 || Convert.ToDouble(txtYongShuiJ2.Text) < 0)
            {
                rs.Msg = "用水价不能为空";
                txtYongShuiJ2.Focus(); return rs;
            }
            if (dKaoHeFY2.Value == null || dKaoHeFY2.Value.ToString().Trim().Length == 0)
            {
                rs.Msg = "请选择考核复用";
                dKaoHeFY2.Focus(); return rs;
            }
            if (cTuoShou2.Checked)
            {
                if (txtKaiHuHM2.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户户名不能为空";
                    txtKaiHuHM2.Focus(); return rs;
                }
                if (txtKaiHuYH2.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户银行不能为空";
                    txtKaiHuYH2.Focus(); return rs;
                }
                if (txtKaiHuZH2.Text.Trim().Length == 0)
                {
                    rs.Msg = "开户账号不能为空";
                    txtKaiHuZH2.Focus(); return rs;
                }
                if (txtHeTongH2.Text.Trim().Length == 0)
                {
                    rs.Msg = "合同号不能为空";
                    txtHeTongH2.Focus(); return rs;
                }
            }
            
            

            if (cQiYongFH3.Checked)
            {
                
                if (txtYongHuH3.Text.Trim().Length == 0)
                {
                    rs.Msg = "用户号不能为空";
                    txtYongHuH3.Focus(); return rs;
                }
                if (txtYongHuM3.Text.Trim().Length == 0)
                {
                    rs.Msg = "用户名不能为空";
                    txtYongHuM3.Focus(); return rs;
                }
                if (txtDiZhi3.Text.Trim().Length == 0)
                {
                    rs.Msg = "地址不能为空";
                    txtDiZhi3.Focus(); return rs;
                }
                if (dXingZhengQ3.Value == null || dXingZhengQ3.Value.ToString().Trim().Length == 0)
                {
                    rs.Msg = "请选择行政区";
                    dXingZhengQ3.Focus(); return rs;
                }
                if (dJuHao3.Value == null || dJuHao3.Value.ToString().Trim().Length == 0)
                {
                    rs.Msg = "请选择局号";
                    dJuHao3.Focus(); return rs;
                }
                //if (dGongSiH3.Value == null || dGongSiH3.Value.ToString().Trim().Length == 0)
                //{
                //    rs.Msg = "请选择公司号";
                //    dGongSiH3.Focus(); return rs;
                //}
                if (dYeWuY3.Value == null || dYeWuY3.Value.ToString().Trim().Length == 0)
                {
                    rs.Msg = "请选择业务员";
                    dYeWuY3.Focus(); return rs;
                }
                if (txtLianXiR3.Text.Trim().Length == 0)
                {
                    rs.Msg = "联系人不能为空";
                    txtLianXiR3.Focus(); return rs;
                }
                if (txtLianXiDH3.Text.Trim().Length == 0)
                {
                    rs.Msg = "联系电话不能为空";
                    txtLianXiDH3.Focus(); return rs;
                }
                if (txtLianXiBM3.Text.Trim().Length == 0)
                {
                    rs.Msg = "联系部门不能为空";
                    txtLianXiBM3.Focus(); return rs;
                }
                if (txtYouBian3.Text.Trim().Length == 0)
                {
                    rs.Msg = "邮编不能为空";
                    txtYouBian3.Focus(); return rs;
                }
                if (dYongShuiXZ3.Value == null || dYongShuiXZ3.Value.ToString().Trim().Length == 0)
                {
                    rs.Msg = "请选择用水性质";
                    dYongShuiXZ3.Focus(); return rs;
                }
                if (dHangYeLB3.Value == null || dHangYeLB3.Value.ToString().Trim().Length == 0)
                {
                    rs.Msg = "请选择行业类别";
                    dHangYeLB3.Focus(); return rs;
                }
                if (txtYongShuiJ3.Text.Trim().Length == 0 || Convert.ToDouble(txtYongShuiJ3.Text) < 0)
                {
                    rs.Msg = "用水价不能为空";
                    txtYongShuiJ3.Focus(); return rs;
                }
                if (dKaoHeFY3.Value == null || dKaoHeFY3.Value.ToString().Trim().Length == 0)
                {
                    rs.Msg = "请选择考核复用"; return rs;
                    dKaoHeFY3.Focus();
                }
                
                if (cTuoShou3.Checked)
                {
                    if (txtKaiHuHM3.Text.Trim().Length == 0)
                    {
                        rs.Msg = "开户户名不能为空";
                        txtKaiHuHM3.Focus(); return rs;
                    }
                    if (txtKaiHuYH3.Text.Trim().Length == 0)
                    {
                        rs.Msg = "开户银行不能为空";
                        txtKaiHuYH3.Focus(); return rs;
                    }
                    if (txtKaiHuZH3.Text.Trim().Length == 0)
                    {
                        rs.Msg = "开户账号不能为空";
                        txtKaiHuZH3.Focus(); return rs;
                    }
                    if (txtHeTongH3.Text.Trim().Length == 0)
                    {
                        rs.Msg = "合同号不能为空";
                        txtHeTongH3.Focus(); return rs;
                    }
                }
            }
            int type = 0;
            string msg = "";
            if (!CheckYongHuHIsUsed(out type, out msg))
            {
                rs.Msg = msg;
                if (type == 1)
                {
                    txtYongHuH1.Focus();
                }
                else if (type == 2)
                {
                    txtYongHuH2.Focus();
                }
                else if (type == 3)
                {
                    txtYongHuH3.Focus();
                }
                return rs;
            }
            rs.IsSuccess = true;
            return rs;
            //throw new NotImplementedException();
        }

        public void ClearInfo()
        {
            ControlCollection controls = this.Controls;

            ControlCollection controls1 = td_FenHu1.Controls;

            ControlCollection controls2 = td_FenHu2.Controls;

            ControlCollection controls3 = td_FenHu3.Controls;
               
            foreach (Control c in controls1)
            {
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox txt = c as DevExpress.Web.ASPxTextBox;
                    txt.Text = "";
                    
                }
                else
                    if (c is DevExpress.Web.ASPxComboBox)
                    {
                        DevExpress.Web.ASPxComboBox com = c as DevExpress.Web.ASPxComboBox;

                        com.SelectedIndex = -1;

                    }
                    else
                        if (c is DevExpress.Web.ASPxCheckBox)
                        {
                            DevExpress.Web.ASPxCheckBox check = c as DevExpress.Web.ASPxCheckBox;

                            check.Checked = false;

                        }

            }
            foreach (Control c in controls2)
            {
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox txt = c as DevExpress.Web.ASPxTextBox;
                    txt.Text = "";

                }
                else
                    if (c is DevExpress.Web.ASPxComboBox)
                    {
                        DevExpress.Web.ASPxComboBox com = c as DevExpress.Web.ASPxComboBox;

                        com.SelectedIndex = -1;

                    }
                    else
                        if (c is DevExpress.Web.ASPxCheckBox)
                        {
                            DevExpress.Web.ASPxCheckBox check = c as DevExpress.Web.ASPxCheckBox;

                            check.Checked = false;

                        }

            }
            foreach (Control c in controls3)
            {
                if (c is DevExpress.Web.ASPxTextBox)
                {
                    DevExpress.Web.ASPxTextBox txt = c as DevExpress.Web.ASPxTextBox;
                    txt.Text = "";

                }
                else
                    if (c is DevExpress.Web.ASPxComboBox)
                    {
                        DevExpress.Web.ASPxComboBox com = c as DevExpress.Web.ASPxComboBox;

                        com.SelectedIndex = -1;

                    }
                    else
                        if (c is DevExpress.Web.ASPxCheckBox)
                        {
                            DevExpress.Web.ASPxCheckBox check = c as DevExpress.Web.ASPxCheckBox;

                            check.Checked = false;

                        }

            }
        }
        /// <summary>
        /// 修改绑定用户信息
        /// </summary>
        public void LoadLaiHanXXByID()
        {
            int id = 0;
            if (!int.TryParse(LaiHanID, out id))
            {
                PageTools.AlertMsg(this,"参数错误","window.close();");
                return;
            }
            HiddenFieldList.Set("QiYongYH3", cQiYongFH3.Checked ? "1" : "0");
            YS_LH_LAIHANXX laihanxx = BllLaiHanxx.SelectYS_LH_LAIHANXX(id);
            if (laihanxx == null)
            {
                PageTools.AlertMsg(this, "相关来函信息不存在", "window.close();");
                return;
            }
            HiddenFieldList.Set("LaiHanBH", laihanxx.S_LAIHANBH);
            txtLaiHanBH.Text = laihanxx.S_LAIHANBH;
            txtYongHuH.Text = laihanxx.S_YONGHUBH;

            PageTools.SetDisabled(txtYongHuH, true);
            PageTools.SetDisabled(txtYongHuH1, true);
            PageTools.SetDisabled(txtYongHuH2, true);
            PageTools.SetDisabled(txtYongHuH3, true);
            LaiHanID = laihanxx.ID.ToString();
            LaiHanLCBH = (eLaiHanLCBH)laihanxx.I_LIUCHENGBH;

            if ((int)LaiHanLCBH == (int)eLaiHanLCBH.预登记)
            {
                SetControlStatus(1, true);
                SetControlStatus(2, true);
                if (cQiYongFH3.Checked)
                {
                    SetControlStatus(3, true);
                }
               
            }
            else
            {
                SetControlStatus(1, false);
                SetControlStatus(2, false);
                SetControlStatus(3, false);
                cQiYongFH3.Enabled = false;
                

            }
            IUCLHOperate uc = this.Parent.FindControl("UCLHBtnBottom") as UCLHBtnBottom;
            if (uc != null)
            {
                uc.LoadInfo(laihanxx);
            }
            uc = this.Parent.FindControl("UCLHSJBTNS") as UCLHSJBTNS;
            if (uc != null)
            {
                uc.LoadInfo(laihanxx);
            }
            LoadYongHuTiaoZheng(laihanxx);

        }
        /// <summary>
        /// 修改绑定用户信息
        /// </summary>
        /// <param name="laihanxx"></param>
        private void LoadYongHuTiaoZheng(YS_LH_LAIHANXX laihanxx)
        {
            string wherecase = " S_YONGHUH='{0}' and i_jlzt=0 and i_leixing=0 and (S_ZHANDIANBH='{1}' or '00'='{1}') ";
            wherecase = string.Format(wherecase,laihanxx.S_YONGHUBH,BusinessTool.ZHANDIANBH());
            DataTable YongHuTable = BllYongHu.SelectYS_YG_YONGHUXXesDynamic(wherecase,"",null);
            if (YongHuTable != null && YongHuTable.Rows.Count > 0)
            {
                HiddenFieldList.Set("YongHuH", YongHuTable.Rows[0]["S_YongHuH"]);
                HiddenFieldList.Set("GUANLIK", YongHuTable.Rows[0]["S_GUANLIKBH"]);
                HiddenFieldList.Set("ZHANDIAN", YongHuTable.Rows[0]["S_ZHANDIANBH"]);
            }
            else
            {
                PageTools.AlertMsg(this, "相关分户信息不存在", "window.close();");
                return;
            }

            string where = " S_LAIHANBH='{0}' and  S_YUANYONGHuH='{1}' and  S_ZHANDIANBH='{2}' and S_GUANLIKBH='{3}'  and i_jlzt=0 ";

            where = string.Format(where, laihanxx.S_LAIHANBH, laihanxx.S_YONGHUBH, YongHuTable.Rows[0]["S_ZHANDIANBH"], YongHuTable.Rows[0]["S_GUANLIKBH"]);
            DataTable dt = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where," ID  ",null);
            DataTable newdt1 = dt.Clone();
            DataTable newdt2 = dt.Clone();
            DataTable newdt3 = dt.Clone();
            
            UCLHShenQingXX uc = this.Parent.FindControl("UCLHShenQingXX") as UCLHShenQingXX;
            if (uc == null)
            {
                PageTools.AlertMsg(this, "相关分户计划不存在", "window.close();");
                return;
            }
            if (dt != null && dt.Rows.Count > 0)
            {
               
                if (dt.Rows.Count >= 1)
                {
                    DataRow newdr = newdt1.NewRow();
                    foreach (DataColumn c in dt.Columns)
                    {
                        newdr[c.ColumnName] = dt.Rows[0][c.ColumnName];
                    }
                   
                    newdt1.Rows.Add(newdr);
                    SetValueYongHuXX(newdt1,1);
                    txtYongHuH1.Text = dt.Rows[0]["S_YONGHUH"].ToString();
                    uc.SetJiHuaXXBind( HiddenFieldList.Get("YongHuH").ToString(),dt.Rows[0]["S_YONGHUH"].ToString(),1);
                }
                if (dt.Rows.Count >= 2)
                {
                    DataRow newdr = newdt2.NewRow();
                    foreach (DataColumn c in dt.Columns)
                    {
                        newdr[c.ColumnName] = dt.Rows[1][c.ColumnName];
                    }
                    newdt2.Rows.Add(newdr);
                    SetValueYongHuXX(newdt2, 2);
                    txtYongHuH2.Text = dt.Rows[1]["S_YONGHUH"].ToString();
                    uc.SetJiHuaXXBind(HiddenFieldList.Get("YongHuH").ToString(), dt.Rows[1]["S_YONGHUH"].ToString(), 2);
                }
                if (dt.Rows.Count >= 3)
                {
                    cQiYongFH3.Checked = true;
                    DataRow newdr = newdt3.NewRow();
                    foreach (DataColumn c in dt.Columns)
                    {
                        newdr[c.ColumnName] = dt.Rows[2][c.ColumnName];
                    }
                    HiddenFieldList.Set("YongHuHDel", dt.Rows[2]["S_YONGHUH"].ToString());
                    newdt3.Rows.Add(newdr);
                    SetValueYongHuXX(newdt3, 3);
                    txtYongHuH3.Text = dt.Rows[2]["S_YONGHUH"].ToString();
                    uc.SetJiHuaXXBind(HiddenFieldList.Get("YongHuH").ToString(), dt.Rows[2]["S_YONGHUH"].ToString(), 3);
                }
                if (laihanxx.I_LIUCHENGBH > 0)
                {
                    uc.SetEnabledTXT(true);
                }
            }
        }
        public YS_LH_LAIHANXX GetLaiHanXX(bool isadd,int liuchengbh)
        {
            YS_LH_LAIHANXX lhxx = new YS_LH_LAIHANXX();
            if (isadd)
            {
                int waterYM = BusinessTool.GetWaterYM();
                int y = Convert.ToInt32(waterYM.ToString().Substring(0, 4));
                int m = Convert.ToInt32(waterYM.ToString().Substring(4, 2));
                lhxx.ID = 0;
                lhxx.D_CAOZUOSJ = DateTime.Now;
                lhxx.D_LAIHANRQ = DateTime.Now;
                lhxx.D_SHURURQ = DateTime.Now;
                lhxx.I_AUTOTYPE = 0;
                lhxx.I_JLZT = 0;
                lhxx.I_LAIHANLX = 8;
                
                lhxx.I_LIUCHENGZT = 0;
                lhxx.I_M = m;
                lhxx.I_SHANGCHUAN = 0;
                lhxx.I_SHURUR = LoginInfo.CurrentUser.UserID;
                lhxx.I_XIANCHUAN = 0;
                lhxx.I_Y = y;
                lhxx.I_TZY = y;

                string xukebh = "";
                string laihanbh = "";
                string zd, glk, ywy;
                PageTools.GetLHDJZDGLKYWY(HiddenFieldList.Get("YongHuH").ToString(), out zd, out glk, out ywy);
                lhxx.S_ZHANDIANBH = zd;
                lhxx.S_GUANLIKBH = glk;
                lhxx.I_YWY = int.Parse(ywy);
                lhxx.S_YWY = BusinessTool.GetYWYName(ywy);
                DataSet numset = _spHelper.P_YS_LH_XUKEBH(glk, 8, 0, y.ToString(), out xukebh, out laihanbh);
                
                //if (isadd)
                //{
                //    DataSet numset = _spHelper.P_YS_LH_XUKEBH(HiddenFieldList.Get("GUANLIK").ToString(), 8, 0, y.ToString(), out xukebh, out laihanbh);
                //}
                if (HiddenFieldList.Contains("LaiHanBH"))
                {
                    laihanbh = HiddenFieldList.Get("LaiHanBH").ToString();
                }
                if (HiddenFieldList.Contains("XuKeBH"))
                {
                    xukebh = HiddenFieldList.Get("XuKeBH").ToString();
                }
                lhxx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                //lhxx.S_GUANLIKBH = HiddenFieldList.Get("GUANLIK").ToString();
                lhxx.S_LAIHANBH = laihanbh;
                lhxx.S_TONGYIBM = "";
                lhxx.S_XUKEBH = xukebh;
                lhxx.S_YONGHUBH = HiddenFieldList.Get("YongHuH").ToString();
                DataRowCollection drcTemp = new YS_YG_YONGHUXXProcess().SelectYS_YG_YONGHUXXesDynamic("I_JLZT=0 AND I_LEIXING=1 AND S_YONGHUH='" + lhxx.S_YONGHUBH + "'", null).Rows;
                lhxx.S_YONGHUM = Convert.ToString(drcTemp[0]["S_YONGHUM"]);
                lhxx.I_XT = 0;
                //lhxx.S_ZHANDIANBH = HiddenFieldList.Get("ZHANDIAN").ToString();


            }
            else
            {
                lhxx = BllLaiHanxx.SelectYS_LH_LAIHANXX(Convert.ToDecimal(LaiHanID));
            }
            lhxx.I_LIUCHENGBH = liuchengbh;
            lhxx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            lhxx.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            return lhxx;
        }

        public void AddOtherTable(YS_LH_LAIHANXX lhxx)
        {
            UCLHShenQingXX uc = this.Parent.FindControl("UCLHShenQingXX") as UCLHShenQingXX;
            uc.AddFenHuXX(1, lhxx, txtYongHuH1.Text.Trim());
            uc.AddFenHuXX(2, lhxx, txtYongHuH2.Text.Trim());

            InsertYongHuXX(1, lhxx);
            InsertYongHuXX(2, lhxx);

            if (cQiYongFH3.Checked)
            {
                InsertYongHuXX(3, lhxx);
                uc.AddFenHuXX(3, lhxx, txtYongHuH3.Text.Trim());
            }
            else
            {
                UpdateDel(lhxx.S_LAIHANBH);
            }
            AddLaiHanSBGX(lhxx.S_LAIHANBH);

            //AddLiuChengXX(lhxx);
            //_SYS_LOGBLL.Log<YS_LH_LAIHANXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "来函管理-分户流程", operateState, lhxx, null);
            LaiHanID = lhxx.ID.ToString();
        }

        /// <summary>
        /// 添加来函主表信息
        /// </summary>
        /// <param name="type"></param>
        public void AddLaiHanXX(int type)
        {
            YS_LH_LAIHANXX lhxx = new YS_LH_LAIHANXX();
            lhxx.ID = 0;
            OperateState operateState;        

            int waterYM = BusinessTool.GetWaterYM();
            int y = Convert.ToInt32(waterYM.ToString().Substring(0,4));
            int m=Convert.ToInt32(waterYM.ToString().Substring(4,2));

            DataTable dt = BllLaiHanxx.SelectYS_LH_LAIHANXXesDynamic(string.Format(" S_YONGHUBH='{0}'  and I_Y={1} and I_M={2} and I_LAIHANLX=8 ", HiddenFieldList.Get("YongHuH").ToString(), y, m), "", null);
            if (dt != null && dt.Rows.Count > 0)
            {
                if (LaiHanID==""||LaiHanID=="0")
                {
                    PageTools.AlertMsg(this, string.Format("该用户来函已存在，来函编号：{0}", dt.Rows[0]["S_LAIHANBH"]));
                    return;
                }

                lhxx.ID = Convert.ToInt32(Convert.ToInt32(dt.Rows[0]["ID"]));
            }


            string xukebh = "";
            string laihanbh = "";            
            DataSet numset = _spHelper.P_YS_LH_XUKEBH(HiddenFieldList.Get("GUANLIK").ToString(), 8, 0,y.ToString(), out xukebh, out laihanbh);
            if (HiddenFieldList.Contains("LaiHanBH"))
            {
                laihanbh = HiddenFieldList.Get("LaiHanBH").ToString();
            }
            if (HiddenFieldList.Contains("XuKeBH"))
            {
                xukebh = HiddenFieldList.Get("XuKeBH").ToString();
            }
             UCLHShenQingXX uc = this.Parent.FindControl("UCLHShenQingXX") as UCLHShenQingXX;
             UCLHBtnBottom ucbottom = this.Parent.FindControl("UCLHBtnBottom") as UCLHBtnBottom;
             if (uc == null || ucbottom==null)
            {
                PageTools.AlertMsg(this,"页面加载错误");
                return;
            }
            ValidateRS rs= ucbottom.ValidateSubmit(laihanbh, HiddenFieldList.Get("YongHuH").ToString());
            if (!rs.IsSuccess)
            {
                PageTools.AlertMsg(this, rs.Msg);
                return;
            }
            
            lhxx.D_CAOZUOSJ = DateTime.Now;
            lhxx.D_LAIHANRQ = DateTime.Now;
            lhxx.D_SHURURQ = DateTime.Now;
            lhxx.I_AUTOTYPE = 0;
            lhxx.I_JLZT = 0;
            lhxx.I_LAIHANLX = 8;
            lhxx.I_LIUCHENGBH = type;
            lhxx.I_LIUCHENGZT = 0;
            lhxx.I_M = m;
            lhxx.I_SHANGCHUAN = 0;
            lhxx.I_SHURUR = LoginInfo.CurrentUser.UserID;
            lhxx.I_XIANCHUAN = 0;
            lhxx.I_Y = y;
            lhxx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            lhxx.S_GUANLIKBH = HiddenFieldList.Get("GUANLIK").ToString();
            lhxx.S_LAIHANBH = laihanbh;
            lhxx.S_TONGYIBM = "";
            lhxx.S_XUKEBH = xukebh;
            lhxx.S_YONGHUBH = HiddenFieldList.Get("YongHuH").ToString();
            lhxx.S_ZHANDIANBH = HiddenFieldList.Get("ZHANDIAN").ToString();
            operateState = OperateState.Add;
            if (LaiHanID!=""&&LaiHanID!="0")
            {
                lhxx.ID = Convert.ToInt32(LaiHanID);
                operateState = OperateState.Modify;
            }
            //if (BllLaiHanxx.InsertOrUpdate(lhxx))
            {
                ucbottom.SHOUJIAN(lhxx);

                uc.AddFenHuXX(1, lhxx, txtYongHuH1.Text.Trim());
                uc.AddFenHuXX(2, lhxx, txtYongHuH2.Text.Trim());

                InsertYongHuXX(1,lhxx);
                InsertYongHuXX(2, lhxx);

                if (cQiYongFH3.Checked)
                {
                    InsertYongHuXX(3, lhxx);
                    uc.AddFenHuXX(3, lhxx, txtYongHuH3.Text.Trim());
                }
                else
                {
                    UpdateDel(lhxx.S_LAIHANBH);
                }
                AddLaiHanSBGX(lhxx.S_LAIHANBH);
                
                AddLiuChengXX(lhxx);
                _SYS_LOGBLL.Log<YS_LH_LAIHANXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "来函管理-分户流程", operateState, lhxx, null);
                LaiHanID = lhxx.ID.ToString();
               
                //PageTools.AlertMsg(this, "保存成功");
               
            }
        }
        /// <summary>
        /// 添加流程信息
        /// </summary>
        /// <param name="laihanxx"></param>
        private void AddLiuChengXX(YS_LH_LAIHANXX laihanxx)
        {
            YS_LH_LAIHANLCJL lcxx = new YS_LH_LAIHANLCJL();
            lcxx.ID = 0;

            

            string where = " S_LAIHANBH='{0}' and I_LIUCHENGBH={1} and i_JLZT=0 ";
            where = string.Format(where,laihanxx.S_LAIHANBH,laihanxx.I_LIUCHENGBH);
            DataTable dt = BllLiuChengXX.SelectYS_LH_LAIHANLCJLsDynamic(where,"",null);
            if (dt != null && dt.Rows.Count > 0)
            {
                lcxx.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
                
                
            }
            else
            {
                lcxx.D_CAOZUORQ = DateTime.Now;
                lcxx.D_STARTDATE = DateTime.Now;
                lcxx.I_CAOZUOR = LoginInfo.CurrentUser.UserID;
                lcxx.I_JLZT = 0;
                lcxx.I_LAIHANLX = 8;
                lcxx.I_LIUCHENGBH = laihanxx.I_LIUCHENGBH;
                lcxx.S_LAIHANBH = laihanxx.S_LAIHANBH;
                lcxx.S_LIUCHENGMC = laihanxx.I_LIUCHENGBH == 0 ? "预登记" : "登记";
                BllLiuChengXX.InsertOrUpdate(lcxx);
                if (laihanxx.I_LIUCHENGBH == 1)
                {
                    string wherecase = " S_LAIHANBH='{0}' and I_LIUCHENGBH={1} and i_JLZT=0 ";
                    string updateCol = " D_ENDDATE=sysdate,D_CAOZUORQ=sysdate,I_CAOZUOR=" + LoginInfo.CurrentUser.UserID + "";
                    wherecase = string.Format(wherecase, laihanxx.S_LAIHANBH, 0);

                    BllLiuChengXX.UpdateYS_LH_LAIHANLCJLsDynamic(updateCol,where);
                }
            }
            
        }
        /// <summary>
        /// 插入用户调整信息
        /// </summary>
        /// <param name="type"></param>
        /// <param name="laihanxx"></param>
        public void InsertYongHuXX(int type,YS_LH_LAIHANXX laihanxx)
        {
            OperateState operateState;            
            string laihanbh = laihanxx.S_LAIHANBH;
           
            YS_LH_YONGHUTZ yhxx = new YS_LH_YONGHUTZ();
            yhxx.D_CAOZUOSJ = DateTime.Now;
            yhxx.I_JLZT = 0;
            
            yhxx.I_LEIXING = 0;
            yhxx.I_YONGHUZT = 0;
            yhxx.ID = 0;
            yhxx.I_YUANYONGH = 1;
            yhxx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            yhxx.S_YUANYONGHUH = HiddenFieldList.Get("YongHuH").ToString();
            yhxx.S_GUANLIKBH = HiddenFieldList.Get("GUANLIK").ToString();
            yhxx.S_ZHANDIANBH = HiddenFieldList.Get("ZHANDIAN").ToString();
            yhxx.S_LAIHANBH = laihanbh;
            if (type == 1)
            {
                yhxx.S_YONGHUH = txtYongHuH1.Text;
                yhxx.S_YONGHUM = txtYongHuM1.Text;
                yhxx.S_DIZHI = txtDiZhi1.Text;
                yhxx.S_XINGZHENGQBH = dXingZhengQ.Value.ToString();
                yhxx.S_JUBIANH = dJuHao.Value == null ? "" : dJuHao.Value.ToString();

                yhxx.S_GONGSIBH = dGongSiH.Value == null ? "" : dGongSiH.Value.ToString();
                yhxx.S_YEWUY = dYeWuY.Value.ToString();
                yhxx.S_LIANXIR = txtLianXiR.Text;
                yhxx.S_LIANXIDH = txtLianXiDH.Text;
                yhxx.S_LIANXIBM = txtLianXiBM1.Text;

                yhxx.S_YOUBIAN = txtYouBian.Text;
                yhxx.S_YONGSHUIXZ = dYongShuiXZ.Value.ToString();
                yhxx.S_SHESHUIDXDM = dHangYeLB.Value.ToString();
                yhxx.N_YSJ = Convert.ToDouble(txtYongShuiJ.Text);
                yhxx.I_KAOHEFY = Convert.ToInt32(dKaoHeFY.Value);
                
                yhxx.S_KAIHUHM = txtKaiHuHM.Text;
                yhxx.S_KAIHUYH = txtKaiHuYH.Text;  
                yhxx.S_YINHANGZH = txtKaiHuZH.Text;
                yhxx.I_SHOUFEIFS = (cTuoShou.Checked == true ? 1 : 0);
            }
            else if (type == 2)
            {
                yhxx.S_YONGHUH = txtYongHuH2.Text;
                yhxx.S_YONGHUM = txtYongHuM2.Text;
                yhxx.S_DIZHI = txtDiZhi2.Text;
                yhxx.S_XINGZHENGQBH = dXingZhengQ2.Value.ToString();
                yhxx.S_JUBIANH = dJuHao2.Value==null?"":dJuHao2.Value.ToString();

                yhxx.S_GONGSIBH = dGongSiH2.Value == null ? "" : dGongSiH2.Value.ToString();
                yhxx.S_YEWUY = dYeWuY2.Value.ToString();
                yhxx.S_LIANXIR = txtLianXiR2.Text;
                yhxx.S_LIANXIDH = txtLianXiDH2.Text;
                yhxx.S_LIANXIBM = txtLianXiBM2.Text;

                yhxx.S_YOUBIAN = txtYouBian2.Text;
                yhxx.S_YONGSHUIXZ = dYongShuiXZ2.Value.ToString();
                yhxx.S_SHESHUIDXDM = dHangYeLB2.Value.ToString();
                yhxx.N_YSJ = Convert.ToDouble(txtYongShuiJ2.Text);
                yhxx.I_KAOHEFY = Convert.ToInt32(dKaoHeFY2.Value);

                yhxx.S_KAIHUHM = txtKaiHuHM2.Text;
                yhxx.S_KAIHUYH = txtKaiHuYH2.Text;
                yhxx.S_YINHANGZH = txtKaiHuZH2.Text;
                yhxx.I_SHOUFEIFS = (cTuoShou2.Checked == true ? 1 : 0);
            }
            else if (type == 3)
            {
                yhxx.S_YONGHUH = txtYongHuH3.Text;
                yhxx.S_YONGHUM = txtYongHuM3.Text;
                yhxx.S_DIZHI = txtDiZhi3.Text;
                yhxx.S_XINGZHENGQBH = dXingZhengQ3.Value.ToString();
                yhxx.S_JUBIANH = dJuHao3.Value == null ? "" : dJuHao3.Value.ToString();

                yhxx.S_GONGSIBH = dGongSiH3.Value == null ? "" : dGongSiH2.Value.ToString();
                yhxx.S_YEWUY = dYeWuY3.Value.ToString();
                yhxx.S_LIANXIR = txtLianXiR3.Text;
                yhxx.S_LIANXIDH = txtLianXiDH3.Text;
                yhxx.S_LIANXIBM = txtLianXiBM3.Text;

                yhxx.S_YOUBIAN = txtYouBian3.Text;
                yhxx.S_YONGSHUIXZ = dYongShuiXZ3.Value.ToString();
                yhxx.S_SHESHUIDXDM = dHangYeLB3.Value.ToString();
                yhxx.N_YSJ = Convert.ToDouble(txtYongShuiJ3.Text);
                yhxx.I_KAOHEFY = Convert.ToInt32(dKaoHeFY3.Value);

                yhxx.S_KAIHUHM = txtKaiHuHM3.Text;
                yhxx.S_KAIHUYH = txtKaiHuYH3.Text;
                yhxx.S_YINHANGZH = txtKaiHuZH3.Text;
                yhxx.I_SHOUFEIFS = (cTuoShou3.Checked == true ? 1 : 0);
            }
            string where = " S_LAIHANBH='{0}' and S_YONGHUH='{1}' and i_jlzt=0  ";
            where = string.Format(where,laihanbh,yhxx.S_YONGHUH);
            DataTable dt = BllLaiHanYHTZ.SelectYS_LH_YONGHUTZsDynamic(where,null,null);
            if (dt != null && dt.Rows.Count > 0)
            {
                yhxx.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
            }
            if (yhxx.ID == 0)
            {
                operateState = OperateState.Add;
            }
            else
            {
                operateState = OperateState.Modify;
            }
            _SYS_LOGBLL.Log<YS_LH_YONGHUTZ>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "来函管理-分户流程", operateState, yhxx, null);
            if (BllLaiHanYHTZ.InsertOrUpdate(yhxx))
            {
                
 
            }
        }

        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            LaiHanID = laihanxx.ID.ToString();
            LaiHanLCBHZT = laihanxx.I_LIUCHENGBH.ToString();
            LoadLaiHanXXByID();
        }

        
        
        /// <summary>
        /// 绑定计划信息
        /// </summary>
        /// <param name="type"></param>
        public void SetJiHuaXXBind(int type)
        {
            UCLHShenQingXX uc = this.Parent.FindControl("UCLHShenQingXX") as UCLHShenQingXX;
            if (uc != null)
            {
               
                if (type == 0)
                {
                    uc.SetJiHuaXX(txtYongHuH.Text.Trim(),type);
                }
                if (type == 1)
                {
                    uc.SetJiHuaXX(txtYongHuH1.Text.Trim(),type);
                }
                if (type == 2)
                {
                    uc.SetJiHuaXX(txtYongHuH2.Text.Trim(),type);
                }
                if (type == 3)
                {
                    uc.SetJiHuaXX(txtYongHuH3.Text.Trim(),type);
                }
            }
        }
       
        /// <summary>
        /// 加载用户信息
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private string LoadYongHuXX(int type)
        {
            string YongHuH = txtYongHuH.Text.Trim();

            int waterYM = BusinessTool.GetWaterYM();
            int y = Convert.ToInt32(waterYM.ToString().Substring(0, 4));
            int m = Convert.ToInt32(waterYM.ToString().Substring(4, 2));
            
            if (YongHuH.Length == 0)
            {
                return "-1|查询用户号不能为空";
            }
            DataTable dtlh = BllLaiHanxx.SelectYS_LH_LAIHANXXesDynamic(string.Format(" S_YONGHUBH='{0}'  and I_Y={1} and I_M={2} and I_LAIHANLX= " + (int)this.laiHanLX, YongHuH, y, m), "", null);
            if (dtlh != null && dtlh.Rows.Count > 0)
            {
                return string.Format("-2|该用户来函已存在，来函编号：{0}", dtlh.Rows[0]["S_LAIHANBH"]);
            }
            string where = " S_SHUIBIAOBH in (select S_SHUIBIAOBH from YS_CB_YONGHUSBGX a where a.S_YONGHUBH='" + YongHuH + "' ) and i_leixing=0 and i_jlzt=0";
            DataTable dt = BllShuiBiaoXX.SelectYS_CB_SHUIBIAOXXesDynamic(where, "", null);
            if (dt != null && dt.Rows.Count == 1&&(!HiddenFieldList.Contains("IsTrue")||HiddenFieldList.Get("IsTrue").ToString()=="0"))
            {
                return "-3|用户相关水表只存在1个";
            }
            if (dt != null && dt.Rows.Count == 2 && cQiYongFH3.Checked && (!HiddenFieldList.Contains("IsTrue") || HiddenFieldList.Get("IsTrue").ToString() == "0"))
            {
                return "-3|用户相关水表只存在2个";
            }
            if ((dt == null || dt.Rows.Count == 0) && (!HiddenFieldList.Contains("IsTrue") || HiddenFieldList.Get("IsTrue").ToString() == "0"))
            {
                return "-3|无用户相关水表";
            }
            

            string wherecase = " S_YONGHUH='{0}' and i_jlzt=0 and i_leixing=0 and (S_ZHANDIANBH='{1}' or '00'='{1}') ";
            wherecase = string.Format(wherecase,YongHuH,BusinessTool.ZHANDIANBH());
            DataTable YongHuTable = BllYongHu.SelectYS_YG_YONGHUXXesDynamic(wherecase,"",null);
            if (YongHuTable != null && YongHuTable.Rows.Count > 0)
            {
                HiddenFieldList.Set("YongHuH", YongHuTable.Rows[0]["S_YongHuH"]);
                HiddenFieldList.Set("GUANLIK", YongHuTable.Rows[0]["S_GUANLIKBH"]);
                HiddenFieldList.Set("ZHANDIAN", YongHuTable.Rows[0]["S_ZHANDIANBH"]);
                if (type == 1)
                {
                    SetValueYongHuXX(YongHuTable, 1);
                    SetValueYongHuXX(YongHuTable, 2);
                }
                else if (type == 3)
                {
                    SetValueYongHuXX(YongHuTable, 3);
                }
                SetControlStatus(1, true);
                SetControlStatus(2, true);
                SetJiHuaXXBind(0);
                return "1|用户信息查询成功";
            }
            else
            {
                return "-1|查询不到该用户信息";
            }
        }
        /// <summary>
        /// 绑定用户信息
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="type"></param>
        private void SetValueYongHuXX(DataTable dt,int type)
        {
            if (dt != null && dt.Rows.Count > 0)
            {
               
                DataRow dr =dt.Rows[0];
                string HeTongH = _spHelper.P_YS_GETHETONGH(dr["S_YONGHUH"].ToString()).Tables[0].Rows[0][0].ToString();
                HiddenFieldList.Set("ZHANDIAN",dr["S_ZHANDIANBH"]);
                if (type == 1)
                {
                    txtYongHuH1.Text = "";
                    
                    txtYongHuM1.Text = dr["S_YONGHUM"].ToString();
                    txtDiZhi1.Text = dr["S_DIZHI"].ToString();
                    dXingZhengQ.Value = dr["S_XINGZHENGQBH"].ToString();
                    dJuHao.Value = dr["S_JUBIANH"].ToString();
                    LoadGongSiByJu(1);
                    
                    dGongSiH.Value = dr["S_GONGSIBH"].ToString();

                    dYeWuY.Value = dr["S_YEWUY"].ToString();
                    txtLianXiR.Text = dr["S_LIANXIR"].ToString();
                    txtLianXiDH.Text = dr["S_LIANXIDH"].ToString();
                    txtLianXiBM1.Value = dr["S_LIANXIBM"].ToString();
                    txtYouBian.Text = dr["S_YOUBIAN"].ToString();

                    dYongShuiXZ.Value = dr["S_YONGSHUIXZ"].ToString();
                    dHangYeLB.Value = dr["S_SHESHUIDXDM"].ToString();
                    txtYongShuiJ.Text = dr["N_YSJ"].ToString();
                    dKaoHeFY.Value = dr["I_KAOHEFY"].ToString();
                    txtKaiHuHM.Text = dr["S_KAIHUHM"].ToString();

                    txtKaiHuYH.Text = dr["S_KAIHUYH"].ToString();
                    txtKaiHuZH.Text = dr["S_YINHANGZH"].ToString();
                    if (dr["I_SHOUFEIFS"].ToString() == "1")
                    {
                        cTuoShou.Checked = true;
                    }
                    this.txtHeTongH.Text = HeTongH;

                    

                }
                else if (type == 2)
                {
                    txtYongHuH2.Text = "";
                    txtYongHuM2.Text = dr["S_YONGHUM"].ToString();
                    txtDiZhi2.Text = dr["S_DIZHI"].ToString();
                    dXingZhengQ2.Value = dr["S_XINGZHENGQBH"].ToString();
                    dJuHao2.Value = dr["S_JUBIANH"].ToString();
                    LoadGongSiByJu(2);

                    dGongSiH2.Value = dr["S_GONGSIBH"].ToString();

                    dYeWuY2.Value = dr["S_YEWUY"].ToString();
                    txtLianXiR2.Text = dr["S_LIANXIR"].ToString();
                    txtLianXiDH2.Text = dr["S_LIANXIDH"].ToString();
                    txtLianXiBM2.Value = dr["S_LIANXIBM"].ToString();
                    txtYouBian2.Text = dr["S_YOUBIAN"].ToString();

                    dYongShuiXZ2.Value = dr["S_YONGSHUIXZ"].ToString();
                    dHangYeLB2.Value = dr["S_SHESHUIDXDM"].ToString();
                    txtYongShuiJ2.Text = dr["N_YSJ"].ToString();
                    dKaoHeFY2.Value = dr["I_KAOHEFY"].ToString();
                    txtKaiHuHM2.Text = dr["S_KAIHUHM"].ToString();

                    txtKaiHuYH2.Text = dr["S_KAIHUYH"].ToString();
                    txtKaiHuZH2.Text = dr["S_YINHANGZH"].ToString();
                    if (dr["I_SHOUFEIFS"].ToString() == "1")
                    {
                        cTuoShou2.Checked = true;
                    }
                    this.txtHeTongH2.Text = HeTongH;
                    txtYongHuH1.Focus();
                }
                else if (type == 3)
                {
                    txtYongHuH3.Text = "";
                    if (!string.IsNullOrEmpty(Request["id"]))
                    {
                        //txtYongHuH3.Text = dr["S_YONGHUH"].ToString();
                    }
                    txtYongHuM3.Text = dr["S_YONGHUM"].ToString();
                    txtDiZhi3.Text = dr["S_DIZHI"].ToString();
                    dXingZhengQ3.Value = dr["S_XINGZHENGQBH"].ToString();
                    dJuHao3.Value = dr["S_JUBIANH"].ToString();
                    LoadGongSiByJu(3);

                    dGongSiH3.Value = dr["S_GONGSIBH"].ToString();

                    dYeWuY3.Value = dr["S_YEWUY"].ToString();
                    txtLianXiR3.Text = dr["S_LIANXIR"].ToString();
                    txtLianXiDH3.Text = dr["S_LIANXIDH"].ToString();
                    txtLianXiBM3.Value = dr["S_LIANXIBM"].ToString();
                    txtYouBian3.Text = dr["S_YOUBIAN"].ToString();

                    dYongShuiXZ3.Value = dr["S_YONGSHUIXZ"].ToString();
                    dHangYeLB3.Value = dr["S_SHESHUIDXDM"].ToString();
                    txtYongShuiJ3.Text = dr["N_YSJ"].ToString();
                    dKaoHeFY3.Value = dr["I_KAOHEFY"].ToString();
                    txtKaiHuHM3.Text = dr["S_KAIHUHM"].ToString();

                    txtKaiHuYH3.Text = dr["S_KAIHUYH"].ToString();
                    txtKaiHuZH3.Text = dr["S_YINHANGZH"].ToString();
                    if (dr["I_SHOUFEIFS"].ToString() == "1")
                    {
                        cTuoShou3.Checked = true;
                    }
                    this.txtHeTongH3.Text = HeTongH;
                    
                    txtYongHuH3.Focus();
                }
            }
        }

       
        /// <summary>
        /// 水表信息
        /// </summary>
        /// <param name="laihanbh"></param>
        public void AddLaiHanSBGX(string laihanbh)
        {
            string YongHuH1 = txtYongHuH1.Text;
            string YongHuH2 = txtYongHuH2.Text;
            string YongHuH3 = txtYongHuH3.Text;
            //YS_LH_YONGHUSBGX sbgx = new YS_LH_YONGHUSBGX();
            //sbgx.D_CAOZUOSJ = DateTime.Now;
            //sbgx.I_JLZT = 0;
            //sbgx.I_LEIXING = 0;
            //sbgx.I_SHUIBIAOZT = 0;
            //sbgx.ID = 0;
            //sbgx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            //sbgx.S_LAIHANBH = laihanbh;
            string where = " S_LAIHANBH='{0}' and S_YONGHUBH='{1}' ";
            string updatecol = "I_JLZT=-1";
            string updatewhere = "S_LAIHANBH='"+laihanbh+"'";
            BllYongHuSBGX.UpdateYS_LH_YONGHUSBGXesDynamic(updatecol, updatewhere);
            if (Session["DtDataSocure1"] != null)
            {
                DataTable dt1 = Session["DtDataSocure1"] as DataTable;
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt1.Rows)
                    {
                        YS_LH_YONGHUSBGX sbgx = new YS_LH_YONGHUSBGX();
                        sbgx.D_CAOZUOSJ = DateTime.Now;
                        sbgx.I_JLZT = 0;
                        sbgx.I_LEIXING = 0;
                        sbgx.I_SHUIBIAOZT = 0;
                        sbgx.ID = 0;
                        sbgx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                        sbgx.S_LAIHANBH = laihanbh;
                        string wherecase = string.Format(where, laihanbh, YongHuH1);
                        DataTable dt = BllYongHuSBGX.SelectYS_LH_YONGHUSBGXesDynamic(wherecase, "", null);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            sbgx.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
                        }
                        sbgx.S_SHUIBIAOBH = dr["S_SHUIBIAOBH"].ToString();
                        sbgx.S_YONGHUBH = YongHuH1;
                        sbgx.S_ZHANDIANBH = dr["S_ZHANDIANBH"].ToString();
                        BllYongHuSBGX.InsertOrUpdate(sbgx);
                    }
                }

            }
            //sbgx.ID = 0;
            if (Session["DtDataSocure2"] != null)
            {
                DataTable dt1 = Session["DtDataSocure2"] as DataTable;
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt1.Rows)
                    {
                        YS_LH_YONGHUSBGX sbgx = new YS_LH_YONGHUSBGX();
                        sbgx.D_CAOZUOSJ = DateTime.Now;
                        sbgx.I_JLZT = 0;
                        sbgx.I_LEIXING = 0;
                        sbgx.I_SHUIBIAOZT = 0;
                        sbgx.ID = 0;
                        sbgx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                        sbgx.S_LAIHANBH = laihanbh;
                        string wherecase = string.Format(where, laihanbh, YongHuH2);
                        DataTable dt = BllYongHuSBGX.SelectYS_LH_YONGHUSBGXesDynamic(wherecase, "", null);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            sbgx.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
                        }
                        sbgx.S_SHUIBIAOBH = dr["S_SHUIBIAOBH"].ToString();
                        sbgx.S_YONGHUBH = YongHuH2;
                        sbgx.S_ZHANDIANBH = dr["S_ZHANDIANBH"].ToString();
                        BllYongHuSBGX.InsertOrUpdate(sbgx);
                    }
                }

            }
            //sbgx.ID = 0;
            if (Session["DtDataSocure3"] != null && cQiYongFH3.Checked)
            {
                DataTable dt1 = Session["DtDataSocure3"] as DataTable;
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt1.Rows)
                    {
                        YS_LH_YONGHUSBGX sbgx = new YS_LH_YONGHUSBGX();
                        sbgx.D_CAOZUOSJ = DateTime.Now;
                        sbgx.I_JLZT = 0;
                        sbgx.I_LEIXING = 0;
                        sbgx.I_SHUIBIAOZT = 0;
                        sbgx.ID = 0;
                        sbgx.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
                        sbgx.S_LAIHANBH = laihanbh;
                        string wherecase = string.Format(where, laihanbh, YongHuH3);
                        DataTable dt = BllYongHuSBGX.SelectYS_LH_YONGHUSBGXesDynamic(wherecase, "", null);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            sbgx.ID = Convert.ToInt32(dt.Rows[0]["ID"]);
                        }
                        sbgx.S_SHUIBIAOBH = dr["S_SHUIBIAOBH"].ToString();
                        sbgx.S_YONGHUBH = YongHuH3;
                        sbgx.S_ZHANDIANBH = dr["S_ZHANDIANBH"].ToString();
                        BllYongHuSBGX.InsertOrUpdate(sbgx);
                    }
                }

            }
            
        }

        /// <summary>
        /// 根据条件更新去掉的用户相关信息
        /// </summary>
        /// <param name="laihanbh"></param>
        private void UpdateDel(string laihanbh)
        {
            if (HiddenFieldList.Contains("QiYongYH3") && HiddenFieldList.Get("QiYongYH3").ToString() == "1")
            {
                YS_LH_FENHUXXBLL BllFenHuXX = new YS_LH_FENHUXXBLL();
                string delYongHuH = HiddenFieldList.Get("YongHuHDel").ToString();

                string delCol = " i_jlzt=-1 ";
                string delwhere = "  S_LAIHANBH='{0}' and S_YONGHUBH='{1}' ";

                delwhere = string.Format(delwhere,laihanbh,delYongHuH);

                BllYongHuSBGX.UpdateYS_LH_YONGHUSBGXesDynamic(delCol, delwhere);

                string Yhdwhere = "  S_LAIHANBH='{0}' and S_YONGHUH='{1}' ";
                Yhdwhere = string.Format(Yhdwhere, laihanbh, delYongHuH);

                BllLaiHanYHTZ.UpdateYS_LH_YONGHUTZsDynamic(delCol,Yhdwhere);

                string JHdwhere = "  S_LAIHANBH='{0}' and S_YONGHUH='{1}' ";
                JHdwhere = string.Format(JHdwhere, laihanbh, delYongHuH);

                BllFenHuXX.UpdateYS_LH_FENHUXXesDynamic(delCol,JHdwhere);


            }
        }
        #endregion

        
        
    }
}